﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using HGZP.BLL;
using HGZP.Model;
using HGZP.PLL;

namespace SZCB.admin.Illness
{
    public partial class AddIllness : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == false)
            {
                BindIllnessClass();
            }

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            CIllnessBLL myCIllnessBLL = new CIllnessBLL();
            DataTable dt = myCIllnessBLL.F02_SelectHaveWhere("sName = '" + txtName.Text + "'");
            if (dt.Rows.Count > 0)
            {
                string strErrmessage = "该疾病已添加";
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + strErrmessage + "');</script>");
                return;
            }
            if (ddlContentClass.SelectedItem.Text == "----请选择分类----")
            {
                string strErrmessage = "请选择疾病大类";
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + strErrmessage + "');</script>");
                return;

            }


            CIllness myCIllness = new CIllness();
            myCIllness.sGuid = MyFunction.GetNewGuid();
            myCIllness.sName = txtName.Text;
            myCIllness.dCreateDate = DateTime.Now;
            myCIllness.sClassname = ddlContentClass.SelectedItem.Text;
            myCIllness.sClassGuid = ddlContentClass.SelectedValue;
            myCIllness.sBriefLink = txtBrief.Text;
            if (!myCIllnessBLL.F_Insert(myCIllness))
            {
                string strErrmessage = "添加食品失败";
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + strErrmessage + "');</script>");
                return;
            }

        }

        private void BindIllnessClass()
        {
            CIllnessClassBLL myCIllnessClassBLL = new CIllnessClassBLL();
            ddlContentClass.DataSource = myCIllnessClassBLL.F02_SelectHaveWhere("");
            ddlContentClass.DataTextField = myCIllnessClassBLL.sName;
            ddlContentClass.DataValueField = myCIllnessClassBLL.sGuid;
            ddlContentClass.DataBind();
            ListItem listItem = new ListItem();
            listItem.Text = "----请选择疾病大类----";
            listItem.Value = "0";
            ddlContentClass.Items.Add(listItem);
            ddlContentClass.SelectedValue = "0";
        }


    }
}